package com.opensource.component.extend.point.support;

import com.opensource.component.extend.point.anntation.SpecificExtend;
import lombok.SneakyThrows;
import org.springframework.beans.factory.annotation.AnnotatedBeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.context.annotation.ClassPathBeanDefinitionScanner;
import org.springframework.core.type.AnnotationMetadata;
import org.springframework.core.type.filter.AnnotationTypeFilter;

/**
 * RemoteApi扫描器 优先扫描注解添加的扫描器，如果没有则默认应用启动类目录下实现进行扫描
 *
 * @author ZonLen since on 2021/7/1 下午12:03
 */
public class ExtendPointScanner extends ClassPathBeanDefinitionScanner {


    ExtendPointScanner(BeanDefinitionRegistry registry) {
        super(registry, false);
        addIncludeFilter(new AnnotationTypeFilter(SpecificExtend.class));
    }

    /**
     * 判断是否是候选的bean
     */
    @SneakyThrows
    @Override
    public boolean isCandidateComponent(AnnotatedBeanDefinition beanDefinition) {
        final AnnotationMetadata metadata = beanDefinition.getMetadata();
        return metadata.isConcrete();
    }

}
